from django.db import models

# Create your models here.


class BaseModel(models.Model):
    create_time = models.DateTimeField(auto_now_add=True)
    update_time = models.DateTimeField(auto_now=True)


# 账号
# 密码
# 法定人
# 营业时间
# 营业状态
# 状态
# 地址
# 联系方式
# 商家评分

class Merchant(BaseModel):
    title = models.CharField('商铺名称', max_length=100)
    account_number = models.CharField('账号', max_length=100)
    pwd = models.CharField('密码', max_length=1000)
    who = models.CharField('法定人', max_length=50)
    code = models.IntegerField('状态', default=0)
    contact_way = models.CharField('联系方式', max_length=200)

    class Meta:
        db_table = 'merchant'


class MerchantAddress(BaseModel):
    content = models.CharField('商家地址', max_length=500)
    merchant_is = models.ForeignKey(Merchant, on_delete=models.CASCADE, verbose_name='商家外键')

    class Meta:
        db_table = 'merchant_address'


class MerchantGrade(BaseModel):
    grade = models.IntegerField('评分', default=0)
    merchant_is = models.ForeignKey(Merchant, on_delete=models.CASCADE, verbose_name='商家外键')

    class Meta:
        db_table = 'merchant_grade'


# 商品名
# 称销量
# 库存
# 价格
# 图片
# 评论
# 所属类别

class Category(BaseModel):
    name = models.CharField('类型', max_length=50)
    merchant_is = models.ForeignKey(Merchant, on_delete=models.CASCADE, verbose_name='商家外键')

    class Meta:
        db_table = 'merchant_cate'


class Goods(BaseModel):
    name = models.CharField('商品名', max_length=50)
    count = models.IntegerField('销量', default=0)
    having = models.IntegerField('库存', default=0)
    price = models.DecimalField('价格', max_digits=8, decimal_places=2)
    img = models.CharField('图片', max_length=1000)
    cate = models.ForeignKey(Category, on_delete=models.CASCADE, verbose_name='类型外键')
    merchant_is = models.ForeignKey(Merchant, on_delete=models.CASCADE, verbose_name='商家外键')

    class Meta:
        db_table = 'goods'


class Coupon(BaseModel):
    CATE_IS = (
        (1, '满减券'),
        (2, '直减券'),
    )
    title = models.CharField('优惠券名称', max_length=200)
    money = models.DecimalField('金额', max_digits=8, decimal_places=2)
    cate = models.IntegerField('性别', choices=CATE_IS, default=1)
    merchant_is = models.ForeignKey(Merchant, on_delete=models.CASCADE, verbose_name='商家外键')

    class Mete(BaseModel):
        db_table = 'coupon'

